//
//  TJCTabBar.swift
//  aiLingVB
//
//  Created by mac on 17/1/5.
//  Copyright © 2017年 TjcLL. All rights reserved.
//

import UIKit

class TJCTabBar: UITabBar {

    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    private func setUpUI(){
        
        addSubview(composeButton)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        
        let w = UIScreen.main.bounds.width * 0.2
        var index: CGFloat = 0

        for value in subviews {
            if value.isMember(of: NSClassFromString("UITabBarButton")!) {
                value.frame = CGRect(x: index * w, y: value.frame.origin.y, width: w, height: frame.height)
                index += 1
                if index == 2 {
                    index += 1
                }
            }
        }
        composeButton.center.x = UIScreen.main.bounds.width * 0.5
        composeButton.center.y = frame.height * 0.5
    }
    
    lazy var composeButton: UIButton = {
        let btn: UIButton = UIButton()
        
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), for: UIControlState.normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), for: UIControlState.highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), for: UIControlState.normal)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), for: UIControlState.highlighted)
        btn.sizeToFit()
        
        return btn
    }()
}
